﻿#region

using System;
using System.Linq;

using Microsoft.Xna.Framework;

using Pob.GameObjects.PowerUps.General;

#endregion

namespace Pob.GameObjects.PowerUps.Special
{
    internal class PaddleSizePowerUpEffect : PowerUpEffect
    {
        #region Fields

        private readonly Player _playerOwner;

        #endregion

        #region Constructors and Destructors

        public PaddleSizePowerUpEffect(Game game, PowerUp owner, Player player, float start, float lifeTime)
            : base(game, owner, start, lifeTime)
        {
            _playerOwner = player;
        }

        #endregion

        #region Public Methods and Operators

        public override void OnActivation()
        {
        }

        public override void OnDeactivation()
        {
            foreach (var gameComponent in Game.Components.OfType<Paddle>().Where(gameComponent => gameComponent.Owner != _playerOwner))
            {
                gameComponent.Visible = true;
            }
        }

        public override void Update(GameTime gameTime)
        {
            foreach (var gameComponent in Game.Components.OfType<Paddle>().Where(gameComponent => gameComponent.Owner != _playerOwner))
            {
                gameComponent.Visible = Math.Floor(gameTime.TotalGameTime.TotalSeconds) % 2 != 0;
            }

            base.Update(gameTime);
        }

        #endregion
    }
}